﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using System.Collections.ObjectModel;

namespace App1.DataModel
{

    public class GroupTag : App1.Common.BindableBase {

        private string _uniqueId = string.Empty;
        private string _title = string.Empty;
        private string _subtitle = string.Empty;
        private string _description = string.Empty;
        // private ImageSource _image = null;
        private String _imagePath = null;
 
        public GroupTag(String uniqueId, String title, String subtitle, String imagePath, String description)
        {
            this._uniqueId = uniqueId;
            this._title = title;
            this._subtitle = subtitle;
            this._description = description;
            this._imagePath = imagePath;
        }

        public string UniqueId
        {
            get { return this._uniqueId; }
            set { this.SetProperty(ref this._uniqueId, value); }
        }

        public string Title
        {
            get { return this._title; }
            set { this.SetProperty(ref this._title, value); }
        }

        public string Subtitle
        {
            get { return this._subtitle; }
            set { this.SetProperty(ref this._subtitle, value); }
        }
        
        private ObservableCollection<Tag> _Tags = new ObservableCollection<Tag>();
        public ObservableCollection<Tag> Tags {
            get { return this._Tags; }
        }

        public IEnumerable<Tag> TopItems
        {
            // Provides a subset of the full items collection to bind to from a GroupedItemsPage
            // for two reasons: GridView will not virtualize large items collections, and it
            // improves the user experience when browsing through groups with large numbers of
            // items.
            //
            // A maximum of 12 items are displayed because it results in filled grid columns
            // whether there are 1, 2, 3, 4, or 6 rows displayed
            get { return this.Tags.Take(12); }
        }
 

    }

    public class Tag : App1.Common.BindableBase {

        public static Uri _baseUri = new Uri("ms-appx:///");
        private string _uniqueId = string.Empty;
        private string _title = string.Empty;
        private string _subtitle = string.Empty;
        private string _description = string.Empty;
        private ImageSource _image = null;
        private String _imagePath = null;


        public Tag(String uniqueId, String title, String subtitle, String imagePath, String description) {
            this._uniqueId = uniqueId;
            this._title = title;
            this._subtitle = subtitle;
            this._description = description;
            this._imagePath = imagePath;
        }
        public string UniqueId
        {
            get { return this._uniqueId; }
            set { this.SetProperty(ref this._uniqueId, value); }
        }

        public string Title
        {
            get { return this._title; }
            set { this.SetProperty(ref this._title, value); }
        }

        public string Subtitle
        {
            get { return this._subtitle; }
            set { this.SetProperty(ref this._subtitle, value); }
        }

        public ImageSource Image
        {
            get
            {
                if (this._image == null && this._imagePath != null)
                {
                    this._image = new BitmapImage(new Uri(Tag._baseUri, this._imagePath));
                }
                return this._image;
            }
            set
            {
                this._imagePath = null;
                this.SetProperty(ref this._image, value);
            }
        }

        public void SetImage(String path)
        {
            this._image = null;
            this._imagePath = path;
            this.OnPropertyChanged("Image");
        }
    }
}
